package com.ccb.sc.auth;

import com.ccb.sc.constant.AppConst;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ken
 * @version 1.0
 * @date 2020-09-15
 */
@Data
public class Token implements Serializable {

    private Long memberId;
    private String role;

    /**
     * 签名，用来表示唯一性
     */
    private String sign;

    private Long aliveHours;

    private String tokenKey;

    private Map<String, Serializable> ext = new HashMap<>();

    public Serializable getAttribute(String key) {
        return this.ext.get(key);
    }

    public void setAttribute(String key, Serializable value) {
        this.ext.put(key, value);
    }

    public boolean isExists(String key) {
        return this.ext.containsKey(key);
    }

    /**
     * 构建redis key：app:role:memberId
     * @return
     */
    public String getTokenKey() {
        return AppConst.PREFIX_TOKEN_TYPE + ":" + role + ":" + memberId;
    }
}
